
  
#include <gtk/gtk.h>  
#include "handwrite.h"
#include "set_dialog.h"
 #include "rw_config.h" 

int set_dialog(ShuoXie *shuoxie)  
{  
    
    GtkWidget *dialog;  
    GtkWidget *bt_ok;
    GtkWidget *check_up;  
    GtkWidget *bt_hbcolor;
    GtkWidget *bt_bjcolor;
    GtkWidget *tm_scale;
    
    gint result;

    char uifile[256];
    sprintf(uifile,"%s/default.glade",getThemeDir());
    GtkBuilder *builder=gtk_builder_new(); 
    if(!gtk_builder_add_from_file(builder, uifile, NULL)){  
                printf("cannot load UI file!\n");              
            }
    //dialog = gtk_dialog_new_with_buttons("设置",shuoxie->window,GTK_DIALOG_MODAL,GTK_STOCK_OK,GTK_RESPONSE_OK,NULL);  

         
    dialog = GTK_WIDGET(gtk_builder_get_object (builder, "set_dialog"));  
    check_up=GTK_WIDGET(gtk_builder_get_object(builder,"xfup_check"));   
    bt_bjcolor=GTK_WIDGET(gtk_builder_get_object(builder,"bj_rgb"));           
    bt_hbcolor=GTK_WIDGET(gtk_builder_get_object(builder,"hb_rgb")); 
    bt_ok=GTK_WIDGET(gtk_builder_get_object(builder,"set_ok")); 
    tm_scale=GTK_WIDGET(gtk_builder_get_object(builder,"tm_scale"));
    gtk_range_set_range(tm_scale,0.3,1);
    
    gtk_range_set_value(tm_scale,shuoxie->opacity);
    gtk_color_button_set_color(bt_bjcolor, &shuoxie->bj_color);
    gtk_color_button_set_color(bt_hbcolor, &shuoxie->hb_color);
            
    //设置缺省按钮  
    gtk_dialog_add_action_widget(dialog,bt_ok,GTK_RESPONSE_OK);
    gtk_dialog_set_default_response(GTK_DIALOG(dialog),GTK_RESPONSE_OK);     
  
   
    gtk_toggle_button_set_active(check_up,shuoxie->xfup);
  
    gtk_widget_show_all(dialog);  
    g_object_unref(G_OBJECT(builder)); 
    //运行和输出对话框  
    result = gtk_dialog_run(GTK_DIALOG(dialog));  
  
    switch(result){  
        case GTK_RESPONSE_NONE:  
            /*-1 
             * 对话框被窗口管理器销毁或通过gtk_widget_destroy()有其他程序销毁。 
             * 如果构件没有设置一个相应标识，会返回它。 
             */  
            break;  
        case GTK_RESPONSE_REJECT:  
            /* -2 
             * 这个标识没有和对话框内置的任何按钮相关联，可以任意使用它 
             * */  
            break;  
        case GTK_RESPONSE_ACCEPT:  
            /* -3 
             * 这个标识没有和对话框内置的任何按钮相关联，可以任意使用它 
             * */  
            break;  
        case GTK_RESPONSE_DELETE_EVENT:  
            /* -4 
             * 每个对话框都会自动连接到delete-event信号，当gtk_dialog_run() 
             * 运行是，这个标识会被返回，而且delete-event会被终止、不会像 
             * 往常那样销毁窗口 
             * */  
            break;  
              
        case GTK_RESPONSE_OK:  
            /* -5 
             * GTK_STOCK_OK 被点击 
             */  
            shuoxie->xfup=gtk_toggle_button_get_active(check_up);
            
            gtk_color_button_get_color(bt_bjcolor, &shuoxie->bj_color);
            gtk_color_button_get_color(bt_hbcolor, &shuoxie->hb_color);
            
            shuoxie->opacity=gtk_range_get_value(tm_scale);
            break;  
        case GTK_RESPONSE_CANCEL:  
            /*-6 
             * GTK_STOCK_CANCEL被点击 
             * */  
            g_print("cancel is press!\n");  
  
            break;  
        case GTK_RESPONSE_CLOSE:  
            /* -7 
             *GTK_STOCK_CLOSE被点击 
             */  
            break;  
        case GTK_RESPONSE_YES:  
            /* -8 
             *GTK_STOCK_YES被点击 
             */  
            break;  
        case GTK_RESPONSE_NO:  
            /* -9 
             *GTK_STOCK_NO被点击 
             */  
            break;  
        case GTK_RESPONSE_APPLY:  
            /* -10 
             *GTK_STOCK_APPLY被点击 
             */  
            break;  
        case GTK_RESPONSE_HELP:  
            /* -11 
             *GTK_STOCK_HELP被点击 
             */  
            break;  
        default:  
            g_print("something wrong!\n");  
  
            break;  
    }  
    
    gtk_widget_destroy(dialog);  
    
    return result;  
}  
